#include "pack_udp.h"
#include "forward_util.h"
#include "common.h"
#include <stdio.h> // NULL

pack_udp::pack_udp(){
	ptr = NULL;
}

pack_udp::pack_udp(void* ptr){
	this->ptr = (udphdr*)ptr;
}

pack_udp::~pack_udp(){

}

uint16_t pack_udp::get_src(){
	return ntohs(ptr->source);
}

uint16_t pack_udp::get_dst(){
	return ntohs(ptr->dest);
}

void pack_udp::set_src(uint16_t port){
	ptr->source = htons(port);
}

void pack_udp::set_dst(uint16_t port){
	ptr->dest = htons(port);
}

uint16_t pack_udp::get_check(){
	return ntohs(ptr->check);
}

uint32_t pack_udp::get_len(){
	return sizeof(struct udphdr);
}

char* pack_udp::get_app_layer(){
	char* p = (char*)(ptr + 1);
	return p;
}

void pack_udp::print_buffer(){

	uint16_t source = get_src();
	uint16_t dest = get_dst();
	uint16_t len = get_len();
	uint16_t check = get_check();

	LOGI("[UDP] source=%u dest=%u len=%u check=%u",
			source,
			dest,
			len,
			check);

	forward_util::print_buff((char*)ptr, len);
}
